#include <stdio.h>
#include <pthread.h>
	
pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond1=PTHREAD_COND_INITIALIZER;
pthread_cond_t cond2=PTHREAD_COND_INITIALIZER;
	
int num=50;
	
void *myfunc1(void *arg)
{
	while(1)	
	{
		pthread_cond_wait(&cond1,&mutex1);
		printf("thread 1 : num=%d\n",num++);
	}
}	
void *myfunc2(void *arg)
{	
	while(1)
	{
		pthread_cond_wait(&cond2,&mutex2);
		printf("thread 2 : num=%d\n",num++);
	}
}	
	
int main(int argc, const char *argv[])
{	
	int inputnum=0;
	pthread_t tid1;
	pthread_t tid2;
	
	pthread_create(&tid1,NULL,myfunc1,NULL);
	pthread_create(&tid2,NULL,myfunc2,NULL);
	while(1)
	{
		scanf("%d",&inputnum);
		switch(inputnum)
		{
			case 1:
				pthread_cond_signal(&cond1);
				break;
			case 2:
				pthread_cond_signal(&cond2);
				break;
		}
	}
	
	return 0;
}	
